package com.itheima.service.impl;

import com.itheima.common.pojo.Member;
import com.itheima.common.pojo.dto.LoginDTO;
import com.itheima.mapper.MemberMapper;
import com.itheima.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class MemberServiceImpl implements MemberService {

    @Autowired
    private MemberMapper memberMapper;

    /**
     * 手机验证码登录
     * @param loginDTO
     */
    public void login(LoginDTO loginDTO) {
        //1.检查是否是会员，如果不是则自动完成注册
        Member member = memberMapper.findByTelephone(loginDTO.getTelephone());
        if (member == null) {
            member = new Member();
            member.setPhoneNumber(loginDTO.getTelephone());
            member.setRegTime(new Date());
            memberMapper.add(member);
        }

    }
}
